<template>
  <div>
    <div class="history" v-if="isShow">
      <div class="top">
        <div class="title"><h4>历史记录</h4></div>
        <div class="delete" @click="clearHistory">
          <van-icon name="delete-o" />
        </div>
      </div>
      <div class="bottom">
        <van-tag
          plain
          type="default"
          v-for="(item, index) in historyKeywordList"
          :key="index"
          @click="tagClick(item)"
          >{{ item }}</van-tag
        >
      </div>
    </div>
    <div class="history">
      <div class="top">
        <div class="title"><h4>热门搜索</h4></div>
      </div>
      <div class="bottom">
        <van-tag
          plain
          :type="item.is_hot == 1 ? 'danger' : 'default'"
          v-for="(item, index) in hotKeywordList"
          :key="index"
          @click="tagClick(item.keyword)"
          >{{ item.keyword }}</van-tag
        >
      </div>
    </div>
  </div>
</template>

<script>
import { clearHistoryData } from "@/request/api.js";
export default {
  props: ["historyKeywordList", "hotKeywordList"],
  data() {
    return {
      isShow: true,
    };
  },
  methods: {
    //标签的点击事件
    tagClick(item) {
      this.$emit("tagClick", item);
    },
    //清空历史记录
    clearHistory() {
      clearHistoryData().then((res) => {
        if (res.errno == 0) {
          this.isShow = false;
          this.$toast("已删除所有的历史记录！");
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
.history {
  background-color: #fff;
  padding: 0 2%;
  margin-top: 10px;
  .top {
    display: flex;
    justify-content: space-between;
    height: 40px;
    line-height: 40px;
  }
  .bottom {
    .van-tag {
      margin-right: 10px;
      margin-bottom: 10px;
      padding: 4px 5px;
      font-size: 14px;
    }
  }
}
</style>